<?php

/**
 * Created by PhpStorm.
 * User: dumbledore
 * Date: 2018/3/7
 * Time: 下午3:24
 */
class Goods extends CI_Controller
{

    public function __construct()
    {
        parent::__construct();
        $this->load->database();
        $this->load->library('form_validation'); //加载表单验证类库
        $this->load->helper('json');
        $this->load->helper('url');
        $this->load->helper('common');
        $this->load->model('user_model');
        $this->load->library('session');
    }

    // 商品详情
    public function detail()
    {
        $customer_id = $this->session->customer_id;
        $id = $_GET['id'];
        if (!$id) {
            exit('该商品不存在');
        }
        $admin_shop_user_id  = $this->user_model->customer_id_to_admin_to_shop_user_id($customer_id);
        $url                 = $this->config->item("shop_url") . 'companymanagerapi/company_goods_info/';
        $data_arr['time']    = time();
        $data_arr['key']     = md5($this->config->item("token_const_wjyh") . $data_arr['time']);
        $data_arr['goodsid'] = $id;
        $data_arr['shop_user_id'] = $admin_shop_user_id;
        $rs                  = curl_request($url, $data_arr);

        $result = json_decode($rs, true);
        if ($result['code'] == 200) {
            $data['data'] = $result['data'];
        } else {
            exit('该商品不存在');
        }
//        $data['data']['goods_atrr'][$data['data']['goods_id']][0]['spec'][0]['goodId']=6702;
        $data['data']['goods_atrr'][$data['data']['goods_id']][1]['spec'][0]['goodId'] = "";

//        echo "<pre>";
        //        print_r( $data['data']);
        //        echo "</pre>";
        $this->load->view('goods/detail', $data);
    }

}
